<template>
  <div class='content'>

    <div class="tables">
      <el-table :data="tableData" stripe style="width: 100%">
        <!-- 设置表头数据源，并循环渲染出来，property对应列内容的字段名 -->
        <el-table-column v-for="info in rightHeader" :key="info.key" :property="info.key" :label="info.label"
                         align="center">
          <template slot-scope="scope">
            <!-- 渲染对应表格里面的内容 -->
            {{ genData(scope)}}
          </template>
        </el-table-column>
        <el-table-column prop="set" label="操作" width="300" fixed="right" align="center">
          <template slot-scope="scope">
            <el-button  type="primary" size="small">修改套餐</el-button>
            <el-button type="danger" @click="centerDialogVisible=true"  size="small">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pages">
      <el-pagination background layout="prev, pager, next" :page-size="10" :total="100"
                     @current-change="handleCurrentChange">
      </el-pagination>
    </div>


    <el-dialog
      title="提示"
      :visible.sync="centerDialogVisible"
      width="20%"
      center>
      <span>确定要删除这个套餐吗</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="centerDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="centerDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    //import引入的组件需要注入到对象中才能使用
    components: {},
    data() {
      //这里存放数据
      return {
        centerDialogVisible:false,
        serchVal: null,
        inventoryType: null,
        rightHeader: [
          {
            key:'name',
            label:'套餐名称'
          },
          {
            key:'content',
            label:'套餐内容'
          },
          {
            key:'price',
            label:'单价'
          },
          {
            key:'totalPrice',
            label:'总价'
          },

        ],
        tableData: [{

              name: '套餐1',
              content: [
                  {name:"库存1",count:1},
                  {name:"库存2",count:2}
                ],
              price: '￥30.00',
              totalPrice: '￥30.00',
        }, ]
      };
    },
    //监听属性 类似于data概念
    computed: {},
    //监控data中的数据变化
    watch: {},
    //方法集合
    methods: {
      handleClick(e) {
        console.log(e)
      },
      handleCurrentChange(e) {
        console.log(e)
      },
      genData(scope){

          if(scope.column.property=="content") {
            let str =  scope.row[scope.column.property].reduce((total,item,index)=>{
              return total+item.name+"*"+item.count+" "
            },"");
            str = str.length>=30?str.substr(0,30)+"...":str

            return str;
          }
          else
            return scope.row[scope.column.property];
      }
    },
    //生命周期 - 创建完成（可以访问当前this实例）
    created() {

    },
    //生命周期 - 挂载完成（可以访问DOM元素）
    mounted() {

    },
    beforeCreate() {}, //生命周期 - 创建之前
    beforeMount() {}, //生命周期 - 挂载之前
    beforeUpdate() {}, //生命周期 - 更新之前
    updated() {}, //生命周期 - 更新之后
    beforeDestroy() {}, //生命周期 - 销毁之前
    destroyed() {}, //生命周期 - 销毁完成
    activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
  }

</script>
<style lang='scss' scoped>
  @import '~@/styles/chow.scss';

</style>
